package com.ruoyi.mall.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mall.domain.OrderReturn;
import com.ruoyi.mall.service.IOrderReturnService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 退货Controller
 * 
 * @author luogongquan
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/orderReturn")
public class OrderReturnController extends BaseController
{
    @Autowired
    private IOrderReturnService orderReturnService;

    /**
     * 查询退货列表
     */
    @RequiresPermissions("mall:orderReturn:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderReturn orderReturn)
    {
        startPage();
        List<OrderReturn> list = orderReturnService.selectOrderReturnList(orderReturn);
        return getDataTable(list);
    }

    /**
     * 导出退货列表
     */
    @RequiresPermissions("mall:orderReturn:export")
    @Log(title = "退货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderReturn orderReturn)
    {
        List<OrderReturn> list = orderReturnService.selectOrderReturnList(orderReturn);
        ExcelUtil<OrderReturn> util = new ExcelUtil<OrderReturn>(OrderReturn.class);
        util.exportExcel(response, list, "退货数据");
    }

    /**
     * 获取退货详细信息
     */
    @RequiresPermissions("mall:orderReturn:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderReturnService.selectOrderReturnById(id));
    }

    /**
     * 新增退货
     */
    @RequiresPermissions("mall:orderReturn:add")
    @Log(title = "退货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderReturn orderReturn)
    {
        return toAjax(orderReturnService.insertOrderReturn(orderReturn));
    }

    /**
     * 修改退货
     */
    @RequiresPermissions("mall:orderReturn:edit")
    @Log(title = "退货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderReturn orderReturn)
    {
        return toAjax(orderReturnService.updateOrderReturn(orderReturn));
    }

    /**
     * 删除退货
     */
    @RequiresPermissions("mall:orderReturn:remove")
    @Log(title = "退货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderReturnService.deleteOrderReturnByIds(ids));
    }

    /**
     * 申请退款
     * @return
     */
    @PostMapping("wx/apply4Refund")
    public AjaxResult apply4Refund(@RequestBody OrderReturn orderReturn){
        return success(orderReturnService.apply4Refund(orderReturn));
    }

    /**
     * 确认退款
     * @return
     */
    @RequiresPermissions("mall:orderReturn:edit")
    @PostMapping("/sureRefund")
    public AjaxResult sureRefund(@RequestBody OrderReturn orderReturn){
        return success(orderReturnService.sureRefund(orderReturn));
    }
    /**
     * 拒绝退款
     * @return
     */
    @RequiresPermissions("mall:orderReturn:edit")
    @PostMapping("/refuseRefund")
    public AjaxResult refuseRefund(@RequestBody OrderReturn orderReturn){
        return success(orderReturnService.refuseRefund(orderReturn));
    }
}
